<template>
  <div class="content">
    <van-notice-bar
      left-icon="volume-o"
      text="本目录下的电影根据上架时间排列,建议支持分享,且看且珍惜!"
    />
    <div class="hot">
      <p>最不受期待的电影</p>
      <div class="bannerList">
        <div
          class="bannerInfo"
          v-for="item in randomHots"
          :key="item"
          @click="moveInfo(item)"
        >
          <div class="bannerImg">
            <img :src="item.poster" alt="" />
            <p>观众评分 {{ item.grade }}</p>
          </div>
          <h3 class="van-ellipsis">{{ item.name }}</h3>
        </div>
      </div>
    </div>
    <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in randomList" :key="item">
        <div class="movieList" @click="moveInfo(item)">
          <div class="movieImg">
            <img :src="item.poster" alt="" />
          </div>
          <div class="movieInfo">
            <div class="movieFn">
              <div class="movieName">
                <p class="van-ellipsis">{{ item.name }}</p>
                <van-tag mark type="primary" color="#4f98d1">{{
                  item.item.name
                }}</van-tag>
              </div>
              <div>
                观众评分: <span class="pingfe">{{ item.grade }}</span>
              </div>
              <div>
                主演:
                <span v-for="actors in item.actors.slice(1, 4)" :key="actors"
                  >{{ actors.name }}&nbsp;
                </span>
              </div>
              <div>上映时间 : {{ getLocalTime(item.premiereAt * 1000) }}</div>
            </div>
            <div class="moviebtn" @click.stop="showShare = true">支持</div>
          </div>
        </div>
      </van-cell>
    </van-list>
    <van-share-sheet
      v-model:show="showShare"
      title="立即分享给好友"
      :options="options"
      @select="onSelect"
      :overlay-style="overlayStyle"
    />
    <van-dialog
      v-model:show="show"
      width="90%"
      :showConfirmButton="false"
      :close-on-click-overlay="true"
      @close="closeInfo"
    >
      <div class="dialog-Info">
        <!-- 弹窗头 -->
        <div class="dialog-Img">
          <img :src="dialogInfo.poster" alt="" />
          <div class="dialog-imginfo">
            <h3>{{ dialogInfo.name }}</h3>
            <p>{{ dialogInfo.category.split('|').join('   ') }}</p>
            <p>
              <span
                v-for="actors in dialogInfo.actors.slice(1)"
                :key="actors.avatarAddress"
                >{{ actors.name + ' ' }}</span
              >
            </p>
            <p class="van-ellipsis">
              {{
                getLocalTime(dialogInfo.premiereAt * 1000) +
                ' ' +
                dialogInfo.nation +
                ' '
              }}
            </p>
            <p>
              {{
                (dialogInfo.runtime === 0 ? '99' : dialogInfo.runtime) +
                '分钟 ' +
                dialogInfo.language
              }}
            </p>
            <div>
              <CountTo
                :startVal="num"
                :endVal="parseInt(dialogInfo.premiereAt / 1000)"
                :duration="2000"
                class="see"
              ></CountTo>
              <span>&nbsp;看过</span>
            </div>
          </div>
        </div>
        <!-- 弹窗简介  -->
        <div class="story">
          <van-row justify="space-between">
            <van-col span="3">简介</van-col>
            <van-col span="4" class="col2" @click="colCut"
              >展开<van-icon :name="overflowLine ? 'arrow-down' : 'arrow-up'" />
            </van-col>
          </van-row>
          <p :class="overflowLine">{{ dialogInfo.synopsis }}</p>
        </div>
        <!-- 弹窗演员  -->
        <div class="actors">
          <van-row justify="space-between">
            <van-col span="10">演职人员</van-col>
          </van-row>
          <div class="actorsList">
            <div
              class="actorsInfo"
              v-for="actors in dialogInfo.actors"
              :key="actors.name"
            >
              <div class="actorsImg">
                <img :src="actors.avatarAddress" alt="" />
                <p>{{ '饰' + actors.role }}</p>
              </div>
              <h3 class="van-ellipsis">{{ actors.name }}</h3>
            </div>
          </div>
        </div>
      </div>
    </van-dialog>
  </div>
</template>

<script setup>
import { onMounted, reactive, ref } from 'vue'
import { useStore } from 'vuex'
import { getMovieList } from '@/api/movie.js'
import { Toast, Dialog } from 'vant'
import { CountTo } from 'vue3-count-to'
const store = useStore()
//信息弹窗------
const VanDialog = Dialog.Component
const show = ref(false)
let dialogInfo = reactive({})
const moveInfo = (item) => {
  dialogInfo = Object.assign(dialogInfo, item) //用这种方法 保持 reactive 的响应式
  console.log(dialogInfo)
  show.value = !show.value
}
//关闭弹窗
const closeInfo = () => {
  //关闭展示
  overflowLine.value = 'van-multi-ellipsis--l3'
  Dialog.close()
}
//弹窗-简介面板=====
//点击事件
const colCut = () => {
  overflowLine.value
    ? (overflowLine.value = '')
    : (overflowLine.value = 'van-multi-ellipsis--l3')
}

const overflowLine = ref('van-multi-ellipsis--l3')
//数字动画效果初始值=====
let num = ref(0)
//分享---------------
const showShare = ref(false)
const onSelect = () => {
  //提示信息
  Toast('分享成功')
  showShare.value = false
}
const options = [
  { name: '微信', icon: 'wechat' },
  { name: '微博', icon: 'weibo' },
  { name: '复制链接', icon: 'link' },
  { name: '分享海报', icon: 'poster' },
  { name: '二维码', icon: 'qrcode' }
]
const overlayStyle = {}
//时间戳
const getLocalTime = (n) => {
  let now = new Date(n),
    y = now.getFullYear(),
    m = now.getMonth() + 1,
    d = now.getDate()
  return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d)
}
//请求数据 功能
onMounted(() => {
  //保证刷新时 不显示另一个页面
  store.commit('movieData/listShowCut', false)
  console.log(randomList)

  getMovieList().then((res) => {
    list = res.data.data.films
    // console.log(list)
    list.sort((a, b) => a.premiereAt - b.premiereAt)
    randomList.value = list.slice(0)
    randomHots.value = list.slice(0)
    randomHots.value.sort((a, b) => Number(a.grade) - Number(b.grade))
  })
})
//列表功能
let list = []
let randomHots = ref([])
let randomList = ref([])
// let listRefs = toRefs(list)
const loading = ref(false)
const finished = ref(false)

const onLoad = () => {
  setTimeout(() => {
    // randomList.value = randomList.value.concat(list.splice(0, 16))
    // 加载状态结束
    // 数据全部加载完成
    if (randomList.value.length >= 30) {
      finished.value = true
    }
    loading.value = false
  }, 1000)
}
</script>

<style lang="scss" scoped>
.dialog-Info {
  height: 70vh;
  background-color: #814646;
  padding: 0.22rem;
  color: #fff;
  overflow: scroll;

  .dialog-Img {
    display: flex;
    height: 1.7rem;
    img {
      height: 100%;
    }
    .dialog-imginfo {
      flex: 1;
      margin-left: 0.14rem;
      display: flex;
      flex-direction: column;
      h3 {
        margin-bottom: 0.1rem;
      }
      p {
        opacity: 0.6;
        font-size: 0.14rem;
        line-height: 0.22rem;
      }
      div {
        margin-top: 0.02rem;
        background-color: rgba(0, 0, 0, 0.18);
        border-radius: 0.16rem;
        flex: 1;
        text-align: center;
        font-size: 0.14rem;
        display: flex;
        justify-content: center;
        align-items: center;
        .see {
          color: #ffb400;
          font-weight: 600;
          font-family: MaoYanHeiTi-H-H;
          font-size: 0.22rem;
          align-self: center;
          opacity: 1;
        }
        span {
          opacity: 0.6;
        }
      }
    }
  }
  .story {
    margin-top: 0.2rem;
    margin-bottom: 0.2rem;
    font-size: 0.14rem;
    .van-col {
      text-align: center;
    }
    .col2 {
      opacity: 0.6;
    }
    p {
      margin-top: 0.1rem;
      padding-left: 0.05rem;
      line-height: 0.24rem;
    }
  }
  .actors {
    font-size: 0.14rem;
    .actorsList {
      overflow: scroll;
      display: flex;
      margin-top: 0.14rem;
      .actorsInfo {
        margin-right: 0.1rem;
        h3 {
          text-align: center;
          font-weight: 400;
          font-size: 0.16rem;
          opacity: 0.8;
        }
      }
      .actorsImg {
        width: 1rem;
        height: 1.45rem;
        position: relative;
        margin-bottom: 0.1rem;

        img {
          width: 100%;
          height: 100%;
        }
        p {
          position: absolute;
          bottom: 0rem;
          color: #faaf00;
          font-size: 0.14rem;
          font-weight: 600;
          width: 100%;
          height: 0.35rem;
          background-image: linear-gradient(-180deg, rgba(77, 77, 77, 0), #000);
          text-align: center;
          box-sizing: border-box;
          padding-top: 0.15rem;
        }
      }
    }
  }
}
.van-cell {
  border-bottom: 0.01rem solid rgb(250, 250, 250);
}
//滚动条
::-webkit-scrollbar {
  display: none;
}
.content {
  background: #f5f5f5;
  //热评
  .hot {
    margin-bottom: 0.1rem;
    background: #fff;
    padding: 12px 15px 12px 15px;
    font-size: 14px;
    color: #333;
    & > p {
      margin-bottom: 12px;
    }
    .bannerList {
      overflow: scroll;
      white-space: nowrap;
      display: flex;
      .bannerInfo {
        margin-right: 0.1rem;
        width: 1rem;
        h3 {
          color: #222;
          font-size: 0.15rem;
          margin-bottom: 0.03rem;
        }

        .bannerImg {
          width: 1rem;
          height: 1.45rem;
          position: relative;
          margin-bottom: 0.1rem;

          img {
            width: 100%;
            height: 100%;
          }
          p {
            position: absolute;
            bottom: 0rem;
            color: #faaf00;
            font-size: 0.14rem;
            font-weight: 600;
            width: 100%;
            height: 0.35rem;
            background-image: linear-gradient(
              -180deg,
              rgba(77, 77, 77, 0),
              #000
            );
            text-align: center;
            box-sizing: border-box;
            padding-top: 0.15rem;
          }
        }
      }
    }
  }
  .movieList {
    display: flex;
    .movieImg {
      height: 1.1rem;
      width: 0.86rem;
      margin-right: 0.14rem;
      img {
        height: 100%;
        width: 100%;
      }
    }
    .movieInfo {
      display: flex;
      flex: 1;
      .movieFn {
        flex: 1;
        .movieName {
          // width: 100%;
          display: flex;
          max-width: 2.17rem;
          margin-bottom: 0.07rem;
          p {
            font-size: 0.18rem;
            color: #333;
            font-weight: 700;
            margin-right: 0.05rem;
            align-self: center;
          }
          .van-tag {
            flex: none;
            align-self: center;
          }
        }
        .pingfe {
          color: #faaf00;
          font-weight: 700;
          font-size: 0.19rem;
        }
      }
      .moviebtn {
        width: 0.5rem;
        background-color: #faaf00;
        color: #fff;
        border-radius: 0.13rem;
        text-align: center;
        align-self: center;
        height: 0.3rem;
        line-height: 0.3rem;
      }
    }
  }
}
</style>
<style>
/* :root {
  --van-overlay-background-color: rgba(20, 20, 20, 0.15);
} */
/* :root {
  --van-dialog-background-color: #663333;
} */
</style>
